package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.brand.DetialVO;
import com.cskaoyan.bean.brand.GoodsDetailVO;
import com.cskaoyan.bean.brand.HomeIndexVO;
import com.cskaoyan.bean.brand.home.CategoryVO;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.VxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("wx")
public class VxGoodsController {
    @Autowired
    VxGoodsService vxGoodsService;

    @RequestMapping("goods/list")
    public BaseRespVo list(String keyword,MarketGoods marketGoods, BasePageInfo info){
        if (keyword != null && !"".equals(keyword)) {
            marketGoods.setKeywords(keyword);
        }
        DetialVO data = vxGoodsService.search(marketGoods,info);
        BaseRespVo ok = BaseRespVo.ok(data);
        ok.setErrmsg("成功");
        return ok;
    }

    @RequestMapping("home/index")
    public BaseRespVo index(){
        HomeIndexVO homeIndexVO = vxGoodsService.searchAll();
        BaseRespVo ok = BaseRespVo.ok(homeIndexVO);
        ok.setErrmsg("成功");
        return ok;
    }

    @RequestMapping("goods/count")
    public BaseRespVo count(){
        int code = vxGoodsService.countAllGoods();
        BaseRespVo ok = BaseRespVo.ok(code);
        ok.setErrmsg("成功");
        return ok;
    }

    @RequestMapping("goods/category")
    public BaseRespVo category(Integer id){
        CategoryVO categoryVO = vxGoodsService.searchCategory(id);
        BaseRespVo ok = BaseRespVo.ok(categoryVO);
        ok.setErrmsg("成功");
        return ok;
    }

    @RequestMapping("goods/detail")
    public BaseRespVo detail(Integer id){
        GoodsDetailVO goodsDetailVO = vxGoodsService.detail(id);
        BaseRespVo ok = BaseRespVo.ok(goodsDetailVO);
        ok.setErrmsg("成功");
        return ok;
    }

    @RequestMapping("goods/related")
    public BaseRespVo related(Integer id){
        CommonData<MarketGoods> data = vxGoodsService.related(id);
        BaseRespVo ok = BaseRespVo.ok(data);
        ok.setErrmsg("成功");
        return ok;
    }
}
